package xyz.flowlight.controller;

import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import xyz.flowlight.domain.response.ResponseResult;
import xyz.flowlight.domain.vo.CartPageVO;
import xyz.flowlight.service.CartService;

@Tag(name = "购物车相关接口")
@RestController
@RequestMapping("/cart")
public class CartController {

    @Resource
    private CartService cartService;


    @PostMapping("/add")
    public ResponseResult<Void> addToCart(@RequestParam Integer productId,
                                          @RequestParam(defaultValue = "1") Integer quantity,
                                          @RequestHeader("userId") Integer userId) {
        return cartService.addToCart(userId, productId, quantity);
    }

    @GetMapping("/list")
    public ResponseResult<CartPageVO> viewCart(@RequestHeader("userId") Integer userId) {
        return cartService.getCartList(userId);
    }

    @PutMapping("/quantity")
    public ResponseResult<Void> updateQuantity(@RequestParam Long cartId, @RequestParam Integer quantity) {
        cartService.updateQuantity(cartId, quantity);
        return ResponseResult.success();
    }

}
